package cn.gjxblog.proxy.spring.utils.demo;

import cn.gjxblog.proxy.spring.utils.HelloService;
import cn.gjxblog.proxy.spring.utils.HelloServiceImpl;
import cn.gjxblog.proxy.spring.utils.TestContext;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.util.ClassUtils;

import java.lang.reflect.Method;

/**
 * TODO...
 *
 * @Author guojiaxun
 * @Date 2019/12/30 18:07
 */
public class AopUtilsDemo {

	public static void main(String[] args) {
		HelloService helloService = TestContext.getProxy(new HelloServiceImpl());

		System.out.println(AopUtils.isAopProxy(helloService));
		System.out.println(AopUtils.isCglibProxy(helloService));
		System.out.println(AopUtils.isJdkDynamicProxy(helloService));

		// 拿到目标对象
		System.out.println(AopUtils.getTargetClass(helloService));

		Method method = ClassUtils.getMethod(HelloServiceImpl.class, "hello");
		System.out.println(AopUtils.selectInvocableMethod(method, HelloServiceImpl.class));

		// 是否是equals方法
		// isToStringMethod、isHashCodeMethod、isFinalizeMethod  都是类似的
		System.out.println(AopUtils.isEqualsMethod(method)); //false

		// 它是对ClassUtils.getMostSpecificMethod,增加了对代理对象的特殊处理。。。
		System.out.println(AopUtils.getMostSpecificMethod(method,HelloService.class));
	}
}
